package com.szqhyxj.youxiangju.biz.register;

import java.util.HashMap;

/**
 * Created by leung on 2018/11/16.
 */

public class UrlParser {
    public static String parse(String url, String key) {
        try {
            //URL url1 = new URL(url);
            if (url.split("\\?").length < 2) {
                return "";
            }
            String queries = url.split("\\?")[1];
            String[] pairs = queries.split("&");
            HashMap<String, String> map = new HashMap<>();
            for (String pair : pairs) {
                String[] kv = pair.split("=");
                if (kv.length != 2) {
                    continue;
                }
                map.put(kv[0], kv[1]);
            }
            return map.get(key);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
